from blog.views import FlexView
from google.appengine.api import users
from google.appengine.ext import webapp
from google.appengine.ext.webapp import template
from google.appengine.ext.webapp.util import run_wsgi_app
import cgi
import logging
import os

games = {
    '/leon' : 'leon',
    '/salas' : 'salas',
    '/alejandro' : 'alejandro',
    '/jorge' : 'jorge',
    '/pablo' : 'pablo',
}

class SimpleLink(object):
    def __init__(self, name, url):
        self.name = name
        self.url = url
        
class MainPage(webapp.RequestHandler):
    def get(self):
        template_values = {
            'main_menu_items' : main_menu_items,
            'site_name' : site_name,
            'main_menu_title' : main_menu_title,
        }
        path = os.path.join(os.path.dirname(__file__), 'views/index.html')
        self.response.out.write(template.render(path, template_values))
        
class GamePage(webapp.RequestHandler):
    def get(self):
        game = games[self.request.path]
        width = 640
        height = 480
        if (game == 'alejandro'):
            width = 840
            height = 680
        
        template_values = {
            'main_menu_items' : main_menu_items,
            'site_name' : site_name,
            'main_menu_title' : main_menu_title,
            'game' : game,
            'width' : width,
            'height' : height,
        }
        path = os.path.join(os.path.dirname(__file__), 'views/gamepage.html')
        self.response.out.write(template.render(path, template_values))

main_menu_items = [    
    SimpleLink('Alejandro','/alejandro'),
    SimpleLink('J. Salas','/salas'),
    SimpleLink('Jorge','/jorge'),
    SimpleLink('Leon','/leon'),
    SimpleLink('Pablo','/pablo'),
    ]

site_name = 'The Costa Rica rainforest game'
main_menu_title = 'Week 1:'
                        
def main():
    logging.getLogger().setLevel(logging.DEBUG)
    application = webapp.WSGIApplication(
        [
            ('/', MainPage),
            ('/salas', GamePage),
            ('/alejandro', GamePage),
            ('/jorge', GamePage),
            ('/leon', GamePage),
            ('/pablo', GamePage),
        ], debug=True)
    run_wsgi_app(application)
    
if __name__ == "__main__":
    main()
